<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class APIPv extends CMiniyunModel
{

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return Yii::app()->params['tablePrefix'].'pv';
	}


	public function relations()
	{
		return array(
		);
	}

	
	public function attributeLabels()
	{
		return array(

		);
	}
	
	public function getPVByDay($currentDate){
		$dbCommand = Yii::app()->db->createCommand("SELECT sum(use_count) as useCount  FROM `".Yii::app()->params['tablePrefix']."pv` where created_at<='".$currentDate." 23:59:59' and created_at>='".$currentDate." 00:00:00'");
		$data =  $dbCommand->query();
		foreach($data as $index=>$item){
			return $item["useCount"];
		}
	}
	
	public function getAppPVByDay($appId,$currentDate){
	    if ($appId == 8){
	        $dbCommand = Yii::app()->db->createCommand("SELECT sum(use_count) as useCount  FROM `".Yii::app()->params['tablePrefix']."pv` where created_at<='".$currentDate." 23:59:59' and created_at>='".$currentDate." 00:00:00' and application_id>=".$appId);
	    }else{
	        $dbCommand = Yii::app()->db->createCommand("SELECT sum(use_count) as useCount  FROM `".Yii::app()->params['tablePrefix']."pv` where created_at<='".$currentDate." 23:59:59' and created_at>='".$currentDate." 00:00:00' and application_id=".$appId);
	    }
	    
		
		$data =  $dbCommand->query();
		foreach($data as $index=>$item){
			return $item["useCount"];
		}
	}
	
	public function getPerformanceByApi($apiId,$currentDate){
		$dbCommand = Yii::app()->db->createCommand("SELECT avg(use_time) as useTime  FROM `".Yii::app()->params['tablePrefix']."pv` where created_at<='".$currentDate." 23:59:59' and created_at>='".$currentDate." 00:00:00' and namespace='".$apiId."'");
		$data =  $dbCommand->query();
		foreach($data as $index=>$item){
			return $item["useTime"];
		}
	}
}